﻿using System.Text.Json;
using Electric.Service.Orders;
using ElectricExceptions;
using Microsoft.AspNetCore.Mvc;

namespace Electric.API.Controllers;

/// <summary>
/// 订单管理
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class OrdersController : ControllerBase
{
    private readonly IOrderService _orderService;

    /// <summary>
    ///
    /// </summary>
    /// <param name="orderService"></param>
    public OrdersController(IOrderService orderService)
    {
        _orderService = orderService;
    }

    /// <summary>
    /// 通过id获取订单
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id}")]
    public IActionResult Get(int id)
    {
        var orderDtos = _orderService.GetById(id);
        if(id < 10){
            throw new BusinessException("this is exception from controller");
        }
        return Ok(orderDtos);
    }
}
